package com.netty.httpService;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * Created by Administrator on 2018/9/7/007.
 */
public class ServiceBootStrap {
    public static void main(String[] args) {
        //接收链接，将连接发送给worker
        EventLoopGroup boosGroup = new NioEventLoopGroup();
        //work线程里面真正完成处理
        EventLoopGroup workGroup = new NioEventLoopGroup();

        try {
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(boosGroup, workGroup);
            //定义一个通道
            bootstrap.channel(NioServerSocketChannel.class);
            //定义一个字处理器
            bootstrap.childHandler(new ServiceInitializer());

            ChannelFuture channelFuture = bootstrap.bind(8899).sync();
            channelFuture.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            boosGroup.shutdownGracefully();

            workGroup.shutdownGracefully();
        }
    }
}
